package com.ly.spring.jdbc.biz;

import com.ly.spring.jdbc.dao.AccountDao;
import com.ly.spring.jdbc.dao.OprecordDao;
import com.ly.spring.jdbc.entity.Oprecored;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/11/11
 * Email haijunzhou@hnit.edu.cn
 */
@Service
public class BankBiz {

    // 存款(deposit), 取款(withdraw), 转账(transfer), 开户(register), 查询(query)

    @Autowired
    AccountDao aDao;
    @Autowired
    OprecordDao oDao;

    @Transactional(rollbackFor = BizException.class ,
                   // rollbackFor => 编译器异常
                   // noRollbackFor => 运行时异常
                   noRollbackFor = ArithmeticException.class)
    // 存款(deposit)
    public void deposit(long id, double money) throws BizException{
        Oprecored oprecored = new Oprecored();
        oprecored.setAid(id);
        oprecored.setOpmoney(money);
        oDao.insert(oprecored);
//        if(money > 5000){
//            // 编译器异常
//            throw new BizException("存款金额大于5000");
//        }
        int i = 1/0;  // 运行时异常
        aDao.updateBalanceById(id, money);
    }


    // 取款(deposit)
    public void withdraw(long id, double money){

    }

    // 转账(transfer)
    public void transfer(long id1, Long id2, double money){

    }
}
